import java.util.*;
public class RepeatedDNASequences {
    public static List<String> findRepeatedDnaSequences(String s) {

        ArrayList<String> result = new ArrayList<String>();

        if(s== null || s.length() == 0) return result;
        
        HashMap<Character,Integer> map = new HashMap<Character,Integer>();
        map.put('A',0);
        map.put('C',1);
        map.put('G',2);
        map.put('T',3);

        HashSet<Integer> hashSet = new HashSet<Integer>();
        Set<Integer> unique = new HashSet<Integer>();
        
        int temp = 0;            
        for(int i=0;i<s.length();i++){
            /*temp = 0;            
            for(int j=0;j<10;j++){
                temp = (temp<<2) + map.get(s.charAt(i+j));
                }*/
            if(i<9){
                temp = (temp<<2) + map.get(s.charAt(i));
            //            System.out.println(temp);
            }
            else{
                temp = (temp<<2) + map.get(s.charAt(i));
                temp &= (1<<20) - 1;
                System.out.println(temp);                
                if(hashSet.contains(temp) && !unique.contains(temp)){
                    result.add(s.substring(i-9,i+1));
                    unique.add(temp);
                }
                else {
                    hashSet.add(temp);
                }
            }
        }
        
        return result;
    }
    
    public static void main(String[] args) {
        String s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT";
        System.out.println(findRepeatedDnaSequences(s));
    }
}
